package com.bumptech.glide;

import android.content.ComponentCallbacks2;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.AssetFileDescriptor;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build.VERSION;
import android.os.ParcelFileDescriptor;
import android.util.Log;
import android.view.View;
import androidx.annotation.GuardedBy;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.bumptech.glide.gifdecoder.GifDecoder;
import com.bumptech.glide.load.resource.bitmap.Downsampler;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import o.aas;
import o.aau;
import o.rh;
import o.ri;
import o.rj;
import o.rp;
import o.rq;
import o.sd;
import o.se;
import o.sq;
import o.to;
import o.uc;
import o.ud;
import o.ut;
import o.uy;
import o.uz;
import o.va;
import o.vb;
import o.ve;
import o.vf;
import o.vh;
import o.vl;
import o.vq;
import o.vq.b;
import o.vq.c;
import o.vr;
import o.vs;
import o.vt;
import o.vu;
import o.vv;
import o.vw;
import o.vy;
import o.wa;
import o.we;
import o.wf;
import o.wj;
import o.wk;
import o.wm;
import o.wp;
import o.ws;
import o.ww;
import o.xa;
import o.xc;
import o.xe;
import o.xf;
import o.xi.a;
import o.xm;
import o.xn;
import o.xo;
import o.xp;
import o.xr;
import o.xt;
import o.xw;
import o.xy;
import o.xz;
import o.ya;
import o.yb;
import o.yc;
import o.ye;
import o.yi;
import o.yt;
import o.yt.e;
import o.yu;
import o.zd;
import o.zn;
import o.zp;
import o.zt;
import o.zz;

public class Glide implements ComponentCallbacks2 {
    private static volatile Glide ˊ;
    private static volatile boolean ॱ;
    private final yt ʻ;
    private final rh ʼ;
    private final ud ʽ;
    private final uc ˋ;
    private rj ˋॱ = rj.NORMAL;
    private final ut ˎ;
    private final to ˏ;
    private final d ͺ;
    private final List<rp> ॱˊ = new ArrayList();
    private final Registry ॱॱ;
    private final yi ᐝ;

    public interface d {
        @NonNull
        zp ˎ();
    }

    @NonNull
    public static Glide ˎ(@NonNull Context context) {
        if (ˊ == null) {
            GeneratedAppGlideModule ˋ = ˋ(context.getApplicationContext());
            synchronized (Glide.class) {
                if (ˊ == null) {
                    ˎ(context, ˋ);
                }
            }
        }
        return ˊ;
    }

    @GuardedBy("Glide.class")
    private static void ˎ(@NonNull Context context, @Nullable GeneratedAppGlideModule generatedAppGlideModule) {
        if (ॱ) {
            throw new IllegalStateException("You cannot call Glide.get() in registerComponents(), use the provided Glide instance instead");
        }
        ॱ = true;
        ˏ(context, generatedAppGlideModule);
        ॱ = false;
    }

    @GuardedBy("Glide.class")
    private static void ˏ(@NonNull Context context, @Nullable GeneratedAppGlideModule generatedAppGlideModule) {
        ˋ(context, new ri(), generatedAppGlideModule);
    }

    @GuardedBy("Glide.class")
    private static void ˋ(@NonNull Context context, @NonNull ri riVar, @Nullable GeneratedAppGlideModule generatedAppGlideModule) {
        yu yuVar;
        e ˏ;
        Context applicationContext = context.getApplicationContext();
        List emptyList = Collections.emptyList();
        List ˊ;
        if (generatedAppGlideModule == null || generatedAppGlideModule.ˋ()) {
            ˊ = new zd(applicationContext).ˊ();
        } else {
            ˊ = emptyList;
        }
        if (!(generatedAppGlideModule == null || generatedAppGlideModule.ˎ().isEmpty())) {
            Set ˎ = generatedAppGlideModule.ˎ();
            Iterator it = r1.iterator();
            while (it.hasNext()) {
                yuVar = (yu) it.next();
                if (ˎ.contains(yuVar.getClass())) {
                    if (Log.isLoggable("Glide", 3)) {
                        Log.d("Glide", "AppGlideModule excludes manifest GlideModule: " + yuVar);
                    }
                    it.remove();
                }
            }
        }
        if (Log.isLoggable("Glide", 3)) {
            for (yu yuVar2 : r1) {
                Log.d("Glide", "Discovered GlideModule from manifest: " + yuVar2.getClass());
            }
        }
        if (generatedAppGlideModule != null) {
            ˏ = generatedAppGlideModule.ˏ();
        } else {
            ˏ = null;
        }
        riVar.ˊ(ˏ);
        for (yu yuVar22 : r1) {
            yuVar22.ˊ(applicationContext, riVar);
        }
        if (generatedAppGlideModule != null) {
            generatedAppGlideModule.ˊ(applicationContext, riVar);
        }
        Object ˎ2 = riVar.ˎ(applicationContext);
        for (yu yuVar222 : r1) {
            try {
                yuVar222.ˎ(applicationContext, ˎ2, ˎ2.ॱॱ);
            } catch (Throwable e) {
                throw new IllegalStateException("Attempting to register a Glide v3 module. If you see this, you or one of your dependencies may be including Glide v3 even though you're using Glide v4. You'll need to find and remove (or update) the offending dependency. The v3 module name is: " + yuVar222.getClass().getName(), e);
            }
        }
        if (generatedAppGlideModule != null) {
            generatedAppGlideModule.ˎ(applicationContext, ˎ2, ˎ2.ॱॱ);
        }
        applicationContext.registerComponentCallbacks(ˎ2);
        ˊ = ˎ2;
    }

    @Nullable
    private static GeneratedAppGlideModule ˋ(Context context) {
        try {
            return (GeneratedAppGlideModule) Class.forName("com.bumptech.glide.GeneratedAppGlideModuleImpl").getDeclaredConstructor(new Class[]{Context.class}).newInstance(new Object[]{context.getApplicationContext()});
        } catch (ClassNotFoundException e) {
            if (Log.isLoggable("Glide", 5)) {
                Log.w("Glide", "Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in your application and a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored");
            }
            return null;
        } catch (Exception e2) {
            ˋ(e2);
            return null;
        } catch (Exception e22) {
            ˋ(e22);
            return null;
        } catch (Exception e222) {
            ˋ(e222);
            return null;
        } catch (Exception e2222) {
            ˋ(e2222);
            return null;
        }
    }

    private static void ˋ(Exception exception) {
        throw new IllegalStateException("GeneratedAppGlideModuleImpl is implemented incorrectly. If you've manually implemented this class, remove your implementation. The Annotation processor will generate a correct implementation.", exception);
    }

    public Glide(@NonNull Context context, @NonNull to toVar, @NonNull ut utVar, @NonNull uc ucVar, @NonNull ud udVar, @NonNull yt ytVar, @NonNull yi yiVar, int i, @NonNull d dVar, @NonNull Map<Class<?>, rq<?, ?>> map, @NonNull List<zn<Object>> list, boolean z, boolean z2, int i2, int i3) {
        se wkVar;
        se xcVar;
        this.ˏ = toVar;
        this.ˋ = ucVar;
        this.ʽ = udVar;
        this.ˎ = utVar;
        this.ʻ = ytVar;
        this.ᐝ = yiVar;
        this.ͺ = dVar;
        Resources resources = context.getResources();
        this.ॱॱ = new Registry();
        this.ॱॱ.ˊ(new wp());
        if (VERSION.SDK_INT >= 27) {
            this.ॱॱ.ˊ(new ws());
        }
        List ˋ = this.ॱॱ.ˋ();
        se xoVar = new xo(context, ˋ, ucVar, udVar);
        se ˊ = xf.ˊ(ucVar);
        if (!z2 || VERSION.SDK_INT < 28) {
            Downsampler downsampler = new Downsampler(this.ॱॱ.ˋ(), resources.getDisplayMetrics(), ucVar, udVar);
            wkVar = new wk(downsampler);
            xcVar = new xc(downsampler, udVar);
        } else {
            xcVar = new xa();
            wkVar = new wm();
        }
        se xnVar = new xn(context);
        vr cVar = new c(resources);
        vr eVar = new vq.e(resources);
        vr dVar2 = new o.vq.d(resources);
        vr bVar = new b(resources);
        sd wjVar = new wj(udVar);
        xz xzVar = new xz();
        ya yaVar = new ya();
        ContentResolver contentResolver = context.getContentResolver();
        Registry ˊ2 = this.ॱॱ.ˋ(ByteBuffer.class, new uz()).ˋ(InputStream.class, new vv(udVar)).ˊ("Bitmap", ByteBuffer.class, Bitmap.class, wkVar).ˊ("Bitmap", InputStream.class, Bitmap.class, xcVar).ˊ("Bitmap", ParcelFileDescriptor.class, Bitmap.class, ˊ).ˊ("Bitmap", AssetFileDescriptor.class, Bitmap.class, xf.ˎ(ucVar)).ˏ(Bitmap.class, Bitmap.class, vu.b.ˏ()).ˊ("Bitmap", Bitmap.class, Bitmap.class, new xe()).ॱ(Bitmap.class, wjVar).ˊ("BitmapDrawable", ByteBuffer.class, BitmapDrawable.class, new we(resources, wkVar));
        we weVar = new we(resources, xcVar);
        ˊ2.ˊ("BitmapDrawable", InputStream.class, BitmapDrawable.class, weVar).ˊ("BitmapDrawable", ParcelFileDescriptor.class, BitmapDrawable.class, new we(resources, ˊ)).ॱ(BitmapDrawable.class, new wf(ucVar, wjVar)).ˊ("Gif", InputStream.class, xt.class, new xy(ˋ, xoVar, udVar)).ˊ("Gif", ByteBuffer.class, xt.class, xoVar).ॱ(xt.class, new xr()).ˏ(GifDecoder.class, GifDecoder.class, vu.b.ˏ()).ˊ("Bitmap", GifDecoder.class, Bitmap.class, new xw(ucVar)).ॱ(Uri.class, Drawable.class, xnVar).ॱ(Uri.class, Bitmap.class, new ww(xnVar, ucVar)).ॱ(new a()).ˏ(File.class, ByteBuffer.class, new va.e()).ˏ(File.class, InputStream.class, new vh.a()).ॱ(File.class, File.class, new xp()).ˏ(File.class, ParcelFileDescriptor.class, new vh.c()).ˏ(File.class, File.class, vu.b.ˏ()).ॱ(new sq.c(udVar)).ˏ(Integer.TYPE, InputStream.class, cVar).ˏ(Integer.TYPE, ParcelFileDescriptor.class, dVar2).ˏ(Integer.class, InputStream.class, cVar).ˏ(Integer.class, ParcelFileDescriptor.class, dVar2).ˏ(Integer.class, Uri.class, eVar).ˏ(Integer.TYPE, AssetFileDescriptor.class, bVar).ˏ(Integer.class, AssetFileDescriptor.class, bVar).ˏ(Integer.TYPE, Uri.class, eVar).ˏ(String.class, InputStream.class, new vf.c()).ˏ(Uri.class, InputStream.class, new vf.c()).ˏ(String.class, InputStream.class, new vt.c()).ˏ(String.class, ParcelFileDescriptor.class, new o.vt.d()).ˏ(String.class, AssetFileDescriptor.class, new vt.e()).ˏ(Uri.class, InputStream.class, new wa.c()).ˏ(Uri.class, InputStream.class, new vb.a(context.getAssets())).ˏ(Uri.class, ParcelFileDescriptor.class, new vb.c(context.getAssets())).ˏ(Uri.class, InputStream.class, new vy.e(context)).ˏ(Uri.class, InputStream.class, new o.wb.d(context)).ˏ(Uri.class, InputStream.class, new vs.b(contentResolver)).ˏ(Uri.class, ParcelFileDescriptor.class, new vs.e(contentResolver)).ˏ(Uri.class, AssetFileDescriptor.class, new vs.c(contentResolver)).ˏ(Uri.class, InputStream.class, new vw.c()).ˏ(URL.class, InputStream.class, new o.vz.d()).ˏ(Uri.class, File.class, new vl.a(context)).ˏ(ve.class, InputStream.class, new o.vx.d()).ˏ(byte[].class, ByteBuffer.class, new uy.a()).ˏ(byte[].class, InputStream.class, new uy.c()).ˏ(Uri.class, Uri.class, vu.b.ˏ()).ˏ(Drawable.class, Drawable.class, vu.b.ˏ()).ॱ(Drawable.class, Drawable.class, new xm()).ॱ(Bitmap.class, BitmapDrawable.class, new yb(resources)).ॱ(Bitmap.class, byte[].class, (yc) xzVar).ॱ(Drawable.class, byte[].class, new ye(ucVar, xzVar, yaVar)).ॱ(xt.class, byte[].class, (yc) yaVar);
        Context context2 = context;
        ud udVar2 = udVar;
        this.ʼ = new rh(context2, udVar2, this.ॱॱ, new zt(), dVar, map, list, toVar, z, i);
    }

    @NonNull
    public uc ˋ() {
        return this.ˋ;
    }

    @NonNull
    public ud ˎ() {
        return this.ʽ;
    }

    @NonNull
    public Context ˏ() {
        return this.ʼ.getBaseContext();
    }

    public yi ˊ() {
        return this.ᐝ;
    }

    @NonNull
    public rh ॱ() {
        return this.ʼ;
    }

    public void ʼ() {
        aau.ॱ();
        this.ˎ.ˋ();
        this.ˋ.ˎ();
        this.ʽ.ˋ();
    }

    public void ॱ(int i) {
        aau.ॱ();
        for (rp onTrimMemory : this.ॱˊ) {
            onTrimMemory.onTrimMemory(i);
        }
        this.ˎ.ˋ(i);
        this.ˋ.ˊ(i);
        this.ʽ.ॱ(i);
    }

    @NonNull
    public yt ʻ() {
        return this.ʻ;
    }

    @NonNull
    private static yt ˊ(@Nullable Context context) {
        aas.ˋ(context, "You cannot start a load on a not yet attached View or a Fragment where getActivity() returns null (which usually occurs when getActivity() is called before the Fragment is attached or after the Fragment is destroyed).");
        return ˎ(context).ʻ();
    }

    @NonNull
    public static rp ˏ(@NonNull Context context) {
        return ˊ(context).ॱ(context);
    }

    @NonNull
    public static rp ˏ(@NonNull View view) {
        return ˊ(view.getContext()).ˋ(view);
    }

    @NonNull
    public Registry ᐝ() {
        return this.ॱॱ;
    }

    public boolean ॱ(@NonNull zz<?> zzVar) {
        synchronized (this.ॱˊ) {
            for (rp ˊ : this.ॱˊ) {
                if (ˊ.ˊ((zz) zzVar)) {
                    return true;
                }
            }
            return false;
        }
    }

    public void ˎ(rp rpVar) {
        synchronized (this.ॱˊ) {
            if (this.ॱˊ.contains(rpVar)) {
                throw new IllegalStateException("Cannot register already registered manager");
            }
            this.ॱˊ.add(rpVar);
        }
    }

    public void ˋ(rp rpVar) {
        synchronized (this.ॱˊ) {
            if (this.ॱˊ.contains(rpVar)) {
                this.ॱˊ.remove(rpVar);
            } else {
                throw new IllegalStateException("Cannot unregister not yet registered manager");
            }
        }
    }

    public void onTrimMemory(int i) {
        ॱ(i);
    }

    public void onConfigurationChanged(Configuration configuration) {
    }

    public void onLowMemory() {
        ʼ();
    }
}
